var columnString = "<tr class='trtab'><td class='tdtab' >" +
    "<span class='tdspan'><span style='color:red'>*</span>字段名：</span>" +
    "<input type='text'   tabindex='5' class='columnName' formatclass='15,^\.+$,1' />" +
    "<span class='input_check' style='color:red'></span>" +
    "</td>" +
    "<td class='tdtab' ><span class='tdspan'>字段code：</span>" +
    "<input type='text'   tabindex='6' class='columnCode'  formatclass='30,^\.+$,1' />" +
    "<span class='input_check' style='color:red'></span>" +
    "</td>" +
	"<td class='tdtab' ><span class='tdspan'>字段类型：</span>" +
    "<input type='text'   tabindex='6' class='columnType' formatclass='15,^\.+$,1' value='String' />" +
    "<span class='input_check' style='color:red'></span>" +
    "</td>"+
    "</tr>";


$(function(){
	
//绑定按钮
submitButton();
columnAdd();


});



function submitButton() {
$("#submit").unbind();
	
$("#submit").click(function(){
	
	if(!submitValidate()){//不匹配时，不用
		alert("不匹配 ");
		return;
	}
	//url 
	url_addTable = "sys/tbInputAction_addTable.action";
	
	var tableName = $("#tableName").attr("value");
	var tableCode = $("#tableCode").attr("value");
	
	var columnsNameDOM = $(".columnName");
	var columnCodeDOM = $(".columnCode");
	var columnTypeDOM = $(".columnType");
	
	
	//拼成字符串
var columnCodeString='';
$.each(columnCodeDOM, function(i, n){
	columnCodeString+=$(n).attr("value")+",";
});

	//拼成字符串
var columnsNameString='';
$.each(columnsNameDOM, function(i, n){
	columnsNameString+=$(n).attr("value")+",";
});

	//拼成字符串
var columnTypeString='';
$.each(columnTypeDOM, function(i, n){
	columnTypeString+=$(n).attr("value")+",";
});

/*
alert(columnsNameString);
alert(columnCodeString);
*/
alert(columnTypeString);



//参数 
	req_addTable = {
		'tableName':tableName,
		'tableCode':tableCode,
		'columnsName':columnsNameString,
		'columnsCode':columnCodeString,
		'columnsType':columnTypeString
	};

	
//提交
	$.post(url_addTable,req_addTable,function(data){
		alert(data.result);
		//location.href="oa/user/users.jsp";
	});

	
});
}



/**
 * 绑定增加字段按钮
 */
function columnAdd() {
	$('#columnAdd').click(function(){
	$('#columnGenrator').append(columnString);
	
	bindInput();//绑定
	
	submitButton();
});
}





